package com.acyouzi.leetcode.string;

import java.util.HashSet;

/**
 * 17/9/11 14:51
 *
 * @author sunxu
 */
public class UniqueCharacter {
  public int firstUniqChar(String s) {
    HashSet<Character> set = new HashSet<>();
    int index = -1;
    for (int i = s.length() - 1; i >=0 ; i--) {
      if (!set.contains(s.charAt(i))){
        index = i;
        set.add(s.charAt(i));
      }else{
        if (index > -1 && s.charAt(index) == s.charAt(i)) index = -1;
      }
    }
    return index;
  }
}
